// 头文件引用
// 官方库
#include <iostream>
#include <limits> // 用于处理输入缓冲区清理

// 项目专用函数库
#include "DownloadCommon.h"
#include "CodeSharingLibrary.h"
#include "GetEnvironmentCommon.h"



// 语言标签 - 多语言支持
std::string* SetProgrammingLanguage_Menu() {

    // 程序应该使用的语言代号
    // 1 - 简体中文
    // 2 - 美式英语
    int UseLang = ObtainTheSystemLanguage();


    // 语言类字符串个数
    std::string static MyProgrammingLanguage_Menu[10];

    // 中文
    if (UseLang == 1) {
        MyProgrammingLanguage_Menu[0] = "欢迎使用新大学生工具箱，请选择要执行的功能：";
        MyProgrammingLanguage_Menu[1] = "[0] 退出程序";
        MyProgrammingLanguage_Menu[2] = "[1] 下载 Visual Studio Code";
        MyProgrammingLanguage_Menu[3] = "[2] 安装 MinGW 开发环境";
        MyProgrammingLanguage_Menu[4] = "[3] 下载 Microsoft Visual Studio";
        MyProgrammingLanguage_Menu[5] = "[4] 安装 Python 开发环境";
        MyProgrammingLanguage_Menu[6] = "[5] 启用/关闭 长路径支持";
        MyProgrammingLanguage_Menu[7] = "[6] 安装 Java 开发环境";
        MyProgrammingLanguage_Menu[8] = "[7] 安装 GoLang 开发环境";
        MyProgrammingLanguage_Menu[9] = "错误：无效选项，请选择 0~7";
    }

    // 其它语言
    else {
        MyProgrammingLanguage_Menu[0] = "Welcome to the New College Student Toolbox. Please select a function to execute:";
        MyProgrammingLanguage_Menu[1] = "[0] Exit";
        MyProgrammingLanguage_Menu[2] = "[1] Download Visual Studio Code";
        MyProgrammingLanguage_Menu[3] = "[2] Install MinGW Development Environment";
        MyProgrammingLanguage_Menu[4] = "[3] Download Microsoft Visual Studio";
        MyProgrammingLanguage_Menu[5] = "[4] Install Python Development Environment";
        MyProgrammingLanguage_Menu[6] = "[5] Configure Long Path Support (Enable/Disable)";
        MyProgrammingLanguage_Menu[7] = "[6] Install Java Development Environment";
        MyProgrammingLanguage_Menu[8] = "[7] Install Java Development Environment";
        MyProgrammingLanguage_Menu[9] = "Error: Invalid selection (Valid options: 0-7)";
    }
    return MyProgrammingLanguage_Menu;
}



// 程序菜单用户层可见区
int Menu() {
    std::string* ProgrammingLanguage_Menu = SetProgrammingLanguage_Menu();
    int UserInput;
    while (true) {
        std::cout << ProgrammingLanguage_Menu[0] << std::endl;
        std::cout << ProgrammingLanguage_Menu[2] << std::endl;
        std::cout << ProgrammingLanguage_Menu[3] << std::endl;
        std::cout << ProgrammingLanguage_Menu[4] << std::endl;
        std::cout << ProgrammingLanguage_Menu[5] << std::endl;
        std::cout << ProgrammingLanguage_Menu[6] << std::endl;
        std::cout << ProgrammingLanguage_Menu[7] << std::endl;
        std::cout << ProgrammingLanguage_Menu[8] << std::endl;
        std::cout << ProgrammingLanguage_Menu[1] << std::endl;
        std::cout << ">> ";

        // 检查输入是否有效
        if (!(std::cin >> UserInput)) {
            // 清除错误状态并忽略错误输入
            std::cin.clear();
            std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
            std::cout << ProgrammingLanguage_Menu[9] << std::endl;
        }
        else {
            if (UserInput>=0 && UserInput<=7) {
                return UserInput;
            }
            else {
                std::cout << ProgrammingLanguage_Menu[9] << std::endl;
            }
        }
    }
}


// 运行程序菜单并引导进入模块
void RunMenu() {
    int GetMenuReturn = Menu();  // 触发菜单并获取返回值

    // 进入菜单中提示的某个模块
    switch (GetMenuReturn) {

        // 退出程序
        case 0:
            break;

        // 模块 - 下载 Visual Studio Code
        case 1:
            Link_VSCode();
            break;

        // 模块 - 安装 MinGW 环境 - 释放 1 次环境变量
        case 2:
            GetEnvironment_MinGW();
            break;

        // 模块 - 下载 Visual Studio Code
        case 3:
            Link_MSVS();
            break;

        // 模块 - 安装 Python 环境 - 释放 2 次环境变量
        case 4:
            GetEnvironment_Python();
            break;

        // 模块 - 类似于 Python 的 开启/关闭 长路径支持
        case 5:
            LenthLimit();
            break;

        // 模块 - 安装 Java 环境 - 释放 1 次环境变量
        case 6:
            GetEnvironment_Java();
            break;

        // 模块 - 安装 GoLang 环境 - 释放 1 次环境变量
        case 7:
            GetEnvironment_GoLang();
            break;

    }

}